package com.gxa.day2022_08_09_28.emp_dept_system.ui.tablemodel;


import javax.swing.table.AbstractTableModel;
//单例 静态内部类方式
/**
 * 管数据和 列头
 */
public class EmpTableModel extends AbstractTableModel {
    private  String[] columnNames = new String[]{"编号","姓名","工种","上级","入职日期","工资","奖金","部门"};
    private Object[][] emps;

    @Override
    public int getRowCount() {//有多少行数据
        return this.emps.length;
    }

    @Override
    public int getColumnCount() {//有多少列
        return this.columnNames.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {//获取单元格的值
        return emps[rowIndex][columnIndex];
    }

    public void setEmps(Object[][] emps) {
        this.emps = emps;
    }

    private EmpTableModel(){}
    private static EmpTableModel empTableModel;

    public static EmpTableModel getInstance(){
        return EmpTableModelHolder.tableModel;
    }

    private static class EmpTableModelHolder{
        private  static final EmpTableModel tableModel = new EmpTableModel();
    }

}
